package servlet;

import pagination.PageBean;
import pojo.Brand;
import service.BrandService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "SelectAllServlet", value = "/SelectAll")
public class SelectAllServlet extends HttpServlet {
    BrandService brandService = new BrandService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

//        0.接收分页的参数（当前是第几页，每一页大小）
        String currentPage = request.getParameter("currentPage");
        int curPage = 1;//默认展示第一页
        if (currentPage!=null){
            curPage = Integer.valueOf(currentPage);
        }
        int pageSize = 5;
        //1. 调用BrandService完成查询
        PageBean<Brand> pageBean = brandService.selectAllPage(curPage,pageSize);
//2. 存入request域中
        request.setAttribute("pageBean",pageBean);
//3. 请求转发到brand.jsp
        request.getRequestDispatcher("/brand.jsp").forward(request,response);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
